/*
 * @ClassName login_register_api.dart
 * @Description 注册登录请求
 * @Author SuPeiSen
 * @Date 2020/7/14 15:40
 */

import 'package:flutter_su/common/request.dart';
import 'package:flutter_su/common/show.dart';
import 'package:flutter_su/config/url_path.dart';
import 'package:flutter_su/model/login_model.dart';

import 'base_api.dart';

class LoginRegisterApi with BaseApi {
  /// 注册api
  Future<bool> register({String userName, String pwd}) async {
    String path = UrlPath.register;
    Show.loading(iconOnTap: showLoadingIconOnTap);
    Map postData = {
      "bslEmail": userName,
      "bslPwd": pwd,
    };
    DioResponseModel dioModel =
        await Request(cancel: cancel).post(path, postData: postData);
    if (dioModel.success == SuccessType.unSuccess) return false;
    return true;
  }

  /// 登录
  Future<LoginModel> login({String bslEmail, String pwd}) async {
    String path = UrlPath.login;
    Show.loading(iconOnTap: showLoadingIconOnTap);
    Map postData = {
      "bslEmail": bslEmail,
      "bslPwd": pwd,
    };
    DioResponseModel dioModel =
        await Request(cancel: cancel).post(path, postData: postData);
    if (dioModel.success == SuccessType.unSuccess) return nullModel;
    return checkToModel<LoginModel>(obj: LoginModel(), map: dioModel.toJson);
  }
}
